#include "mhttp.h"
#include "parkinglotmainwindow.h"
#include <QEventLoop>
MHttp::MHttp(QWidget *parent) : QWidget(parent)
{
    manager=new QNetworkAccessManager(this);
}

bool MHttp::post_sync(QString url, QByteArray &body, QByteArray &replyData)
{
    QNetworkRequest req;
    req.setUrl(url);
    req.setRawHeader(QString("Content-Type").toLatin1(),QString("application/x-www-form-urlencoded").toLatin1());
    QNetworkReply *rep= manager->post(req,body);
    QEventLoop l;
    connect(rep,&QNetworkReply::finished,&l,&QEventLoop::quit);
    l.exec();
    if(rep!=nullptr&&rep->error()==QNetworkReply::NoError){
        replyData=rep->readAll();
        return true;
    }
    else return false;

}

